package com.dxyxx.android.setting;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import br.com.pierry.simpletoast.SimpleToast;

import com.dxyxx.R;
import com.dxyxx.dialog.PhonePlayer;
import com.dxyxx.framework.ExitFromSettings;
import com.dxyxx.framework.FeedbackActivity;
import com.dxyxx.framework.ResultCode;
import com.dxyxx.utils.UpdateManager;

/**
 * 需要对ckeckBox状态进行保存，包括夜间模式，推送模式。
 * 
 * 推送模式的记忆功能是针对机子的，而不是针对个人的，默认是关闭的。 preference 记住了推送开启与否，
 * 所以当某人登陆成功之后，就去检查pushModeOpen,true就开启推送模式。
 * 
 * 而当用户切入设置界面观察 推送模式的checkbox的时候，就要去检查pushModeOpen，true的话就要将打勾显示出来。。。
 * 
 * @author chinesejie
 * 
 */
public class SettingActivity extends Activity {
	final String currentVersion = "0.1";
	private RelativeLayout nightMode;
	private RelativeLayout pushMode;
	private RelativeLayout smsShare;
	private RelativeLayout feedback;
	private RelativeLayout map;
	private RelativeLayout aboutDK;
	private RelativeLayout code;

	private Button logoutButton;
	private CheckBox checkBox;
	private CheckBox pushModeCheckBox;
	private Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		context = this;
		initViews();
	}

	private void initViews() {
		TextView titleView = (TextView) findViewById(R.id.title);
		titleView.setText("系统设置");
		titleView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
		((ImageView) findViewById(R.id.nextImageButton)).setVisibility(View.INVISIBLE);
		ImageView backButton = ((ImageView) findViewById(R.id.backImageButton));
		backButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		logoutButton = (Button) findViewById(R.id.b_setting_page_logout);
		logoutButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(SettingActivity.this, com.dxyxx.framework.ExitFromSettings.class), 1);
				/*
				 * new
				 * EProgressDialogHelper(PageActivity.this).showProgressDialog
				 * (null, "等", null);
				 */
			}
		});

		findViewById(R.id.versionCheck).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				UpdateManager updateManager = new UpdateManager(SettingActivity.this);
				updateManager.checkUpdateInfo();
			}
		});

		findViewById(R.id.feedback).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				startActivity(new Intent(SettingActivity.this, FeedbackActivity.class));
			}
		});
		findViewById(R.id.phoneService).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				PhonePlayer.makeCall((Activity) context, "057588881234");
			}
		});
		
		findViewById(R.id.codeMode).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				 SimpleToast.info(context, "即将推出，敬请等待");
			}
		});
		
		findViewById(R.id.mapMode).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				 SimpleToast.info(context, "即将推出，敬请等待");
			}
		});
		findViewById(R.id.aboutDXYXX).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				 SimpleToast.info(context, "绍兴大象与猩猩\n为您提供优质的服务");
			}
		});

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (data != null) {
			String result = data.getExtras().getString("result");
			if (resultCode == ResultCode.Logout) {
				Intent intent = new Intent();
				// 关闭Activity
				intent.putExtra("result", "sure");
				SettingActivity.this.setResult(ResultCode.Logout, intent);
				SettingActivity.this.finish();
				finish();
			}
		}
	}

}
